| <extend name="public@base"/>
block(name="main")
    php $submenus=$menus;
        | if (!function_exists('getsubmenu')) {
        | function getsubmenu($submenus){
    notempty(name='submenus')
        php foreach($submenus as $menu){ $menu_id='#menu'.$menu['id'];
        li.list-group-item
            php
                | $menu_name=lang($menu['lang']);
                | $menu_name=$menu['lang']==$menu_name?$menu['name']:$menu_name;
            php if(empty($menu['items'])){
            a.text-dark.text-decoration-none(href="javascript:openapp('{$menu.url}','{$menu.id}','{$menu_name}',true);")
                i.fa.fa-fw(class="fa-{$menu.icon|default='desktop'}")
                span.menu-text  {$menu_name}
            php }else{
            a.text-dark.text-decoration-none(href="#" data-toggle="collapse" data-target="{$menu_id}" aria-expanded="false" aria-controls="menu{$menu.id}")
                i.fa.fa-fw(class="fa-{$menu.icon|default='desktop'}")
                span.menu-text  {$menu_name}
                i.fa.fa-angle-right.fa-lg.fa-fw
            ul.submenu.collapse.list-unstyled(id="menu{$menu.id}" data-parent="#left-nav")
                php getsubmenu1($menu['items'])
            php }
        php }
    php }}
    php
        | if (!function_exists('getsubmenu1')) {
        | function getsubmenu1($submenus){
    php foreach($submenus as $menu){ $submenu_id='#submenu'.$menu['id'];
    li
        php
            | $menu_name=lang($menu['lang']);
            | $menu_name=$menu['lang']==$menu_name?$menu['name']:$menu_name;
        php if(empty($menu['items'])){
        a.text-dark.text-decoration-none(href="javascript:openapp('{$menu.url}','{$menu.id}','{$menu_name}',true);")
            i.fa.fa-fw.fa-angle-right
            span.menu-text.py-1
                | {$menu_name}
        php }else{
        a.text-dark.text-decoration-none(href="#" data-toggle="collapse" data-target="{$submenu_id}" aria-expanded="false" aria-controls="submenu{$menu.id}")
            i.fa.fa-fw.fa-angle-right
            span.menu-text.py-1
                | {$menu_name}
        ul.collapse.list-unstyled(id="submenu{$menu.id}" data-parent="{$submenu_id}")
            php getsubmenu2($menu['items'])
        php }
    php }
    php }}
    php
        | if (!function_exists('getsubmenu2')) {
        | function getsubmenu2($submenus){
    php foreach($submenus as $menu){
    li
        php
            | $menu_name=lang($menu['lang']);
            | $menu_name=$menu['lang']==$menu_name?$menu['name']:$menu_name;
        a.text-dark.text-decoration-none.pl-2(href="javascript:openapp('{$menu.url}','{$menu.id}','{$menu_name}',true);")
            i.fa.fa-fw.fa-angle-double-right
            span.menu-text.py-1
                | {$menu_name}
    php }
    php }}
    //- 顶部导航栏
    header.fixed-top#top-bar
        //- 进度条
        #loading.progress
            .progress-bar(role="progress-bar" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100")
        //- 右侧工具栏
        #right-tools-wrapper
        //- 导航栏主体
        .navbar.navbar-expand-lg.p-0.navbar-dark.bg-purple
            a.navbar-brand.pl-5(href="{:url('admin/index/index')}") ThinkCMF
            button.navbar-toggler(type='button', data-toggle='collapse', data-target='#main-nav', aria-controls='main-nav', aria-expanded='false', aria-label='Toggle navigation')
                span.navbar-toggler-icon
            //- 菜单标签列表
            #main-nav.navbar-collapse.collapse.justify-content-between
                #task-main-menu
                    a#task-pre.task-changebt
                        i.fa.fa-chevron-left
                    #task-content
                        ul.navbar-nav#task-content-inner.cmf-component-tab
                            li.cmf-component-tabitem.noclose.nav-item(app-id='0', app-url="{:url('main/index')}", app-name='首页')
                                a.cmf-tabs-item-text.nav-link {:lang('HOME')}
                    a#task-next.task-changebt
                        i.fa.fa-chevron-right
                //- 登录状态
                ul.navbar-nav#login-bar.mr-lg-4
                    li.nav-item#close-all-tabs-btn
                        a.nav-link#close-wrapper(href='javascript:void(0);', title="{:lang('CLOSE_TOP_MENU')}")
                            i.fa.fa-times.right_tool_icon
                    li.nav-item
                        a.nav-link#refresh-wrapper(href='javacript:void(0);', title="{:lang('REFRESH_CURRENT_PAGE')}")
                            i.fa.fa-refresh.right_tool_icon
                    li.nav-item.dropdown
                        a.nav-link.dropdown-toggle(data-toggle='dropdown', href='#')
                            <if condition="isset($admin['avatar']) && $admin['avatar']">
                            .nav-user-photo
                                img(src="{:cmf_get_user_avatar_url($admin['avatar'])}", alt='{$admin.user_login}')
                            <else />
                            .nav-user-photo
                                img(src='__TMPL__/public/assets/images/logo-18.png', alt="{$admin.user_login|default=''}")
                            </if>
                            span.user-info {:lang('WELCOME_USER',array('user_nickname' => empty($admin['user_nickname'] )? $admin['user_login'] : $admin['user_nickname']))}
                        .user-menu.dropdown-menu
                            <if condition="cmf_auth_check(cmf_get_current_admin_id(),'admin/Setting/site')">
                            a.dropdown-item(href="javascript:openapp('{:url('setting/site')}','index_site','{:lang('ADMIN_SETTING_SITE')}');")
                                i.fa.fa-cog
                                | {:lang('ADMIN_SETTING_SITE')}
                            </if>
                            <if condition="cmf_auth_check(cmf_get_current_admin_id(),'admin/user/userinfo')">
                            a.dropdown-item(href="javascript:openapp('{:url('user/userinfo')}','index_userinfo','{:lang('ADMIN_USER_USERINFO')}');")
                                i.fa.fa-user
                                |  {:lang('ADMIN_USER_USERINFO')}
                            </if>
                            <if condition="cmf_auth_check(cmf_get_current_admin_id(),'admin/Setting/password')">
                            a.dropdown-item(href="javascript:openapp('{:url('setting/password')}','index_password','{:lang('ADMIN_SETTING_PASSWORD')}');")
                                i.fa.fa-lock
                                |  {:lang('ADMIN_SETTING_PASSWORD')}
                            </if>
                            a.dropdown-item(href="{:url('Public/logout')}")
                                i.fa.fa-sign-out
                                |  {:lang('LOGOUT')}
    .container-fluid#main-box.h-100
        .row.h-100
            .col-auto#sidebar.border-right.pt-1
                ul.row.list-unstyled#sidebar-shortcuts.sidebar-shortcuts.no-gutters
                    li.col.pr-1
                        a.btn.btn-sm.btn-warning(href='__ROOT__/', title="{:lang('WEBSITE_HOME_PAGE')}", target='_blank', data-toggle='tooltip')
                            i.fa.fa-home
                    li.col.pr-1
                        <if condition="cmf_auth_check(cmf_get_current_admin_id(),'user/AdminAsset/index')">
                        a.btn.btn-sm.btn-info(href="javascript:openapp('{:url('user/AdminAsset/index')}','userAdminAssetindex','资源管理',true);", title='资源管理', data-toggle='tooltip')
                            i.fa.fa-file
                        </if>
                    li.col.pr-1
                        <if condition="cmf_auth_check(cmf_get_current_admin_id(),'admin/Setting/clearcache')">
                        a.btn.btn-sm.btn-danger(href="javascript:openapp('{:url('admin/Setting/clearcache')}','index_clearcache','{:lang('ADMIN_SETTING_CLEARCACHE')}',true);", title="{:lang('ADMIN_SETTING_CLEARCACHE')}", data-toggle='tooltip')
                            i.fa.fa-trash-o
                        </if>
                    li.col.pr-1
                        <if condition="cmf_auth_check(cmf_get_current_admin_id(),'admin/RecycleBin/index')">
                        a.btn.btn-sm.btn-danger(href="javascript:openapp('{:url('admin/RecycleBin/index')}','index_recycle','回收站',true);", title='回收站', data-toggle='tooltip')
                            i.fa.fa-recycle
                        </if>
                    li.col
                        <if condition="APP_DEBUG">
                        a.btn.btn-sm.btn-dark(href="javascript:openapp('{:url('admin/Menu/index')}','index_menu','{:lang('ADMIN_MENU_INDEX')}',true);", title="{:lang('ADMIN_MENU_INDEX')}", data-toggle='tooltip')
                            i.fa.fa-list
                        </if>
                .row
                    .col-12
                        ul#left-nav.list-group
                            | {:getsubmenu($submenus)}
            .main-content.col.pr-0
                #content.page-content.w-100.h-100
                    iframe#appiframe-0.appiframe(src="{:url('Main/index')}", style='width:100%;height: 100%;', frameborder='0')

block(name="bottom-script")
    script.
        console.log("document 宽度：" + $(document).width());
        console.log("window 宽度：" + $(window).width());
    //script.
        $(function () {
            $("[data-toggle='tooltip']").tooltip();
            $("li.dropdown").hover(function () {
                $(this).addClass("open");
            }, function () {
                $(this).removeClass("open");
            });
            var menus = {$menus_js_var}
            ;
            //读取url参数。尝试执行菜单功能。
            if (typeof (menus) != "undefined") {
                var tw = window.top;
                var twa = tw.location.href.split("#");
                var url = twa[1];
                var urlTmp = url;
                if (url != null) {
                    //去掉/ 去掉_ 全部小写。
                    urlTmp = urlTmp.replace(/[\\\/|_|]/g, "");
                    urlTmp = urlTmp.replace(".html", "");
                    var menu = menus[urlTmp];
                    if (menu) {
                        openapp(url, menu.id + menu.app, menu.name, true);
                    }
                }
            }
        });
        var ismenumin = $("#sidebar").hasClass("menu-min");
        $(".nav-list").on("click", function (event) {
            var closest_a = $(event.target).closest("a");
            if (!closest_a || closest_a.length == 0) {
                return
            }
            if (!closest_a.hasClass("dropdown-toggle")) {
                if (ismenumin && "click" == "tap" && closest_a.get(0).parentNode.parentNode == this) {
                    var closest_a_menu_text = closest_a.find(".menu-text").get(0);
                    if (event.target != closest_a_menu_text && !$.contains(closest_a_menu_text, event.target)) {
                        return false
                    }
                }
                return
            }
            var closest_a_next = closest_a.next().get(0);
            if (!$(closest_a_next).is(":visible")) {
                var closest_ul = $(closest_a_next.parentNode).closest("ul");
                if (ismenumin && closest_ul.hasClass("nav-list")) {
                    return
                }
                closest_ul.find("> .open > .submenu").each(function () {
                    if (this != closest_a_next && !$(this.parentNode).hasClass("active")) {
                        $(this).slideUp(150).parent().removeClass("open")
                    }
                });
            }
            if (ismenumin && $(closest_a_next.parentNode.parentNode).hasClass("nav-list")) {
                return false;
            }
            $(closest_a_next).slideToggle(150).parent().toggleClass("open");
            return false;
        });
